<template>
  <div
    class="swiper-item"
    :class="[activeSwiper === item.name ? 'active' : '']"
    @click="swiperChange(item)"
  >
    <div class="item-left">
      <div class="text-1">{{ item.name }}</div>
      <div class="text-2">计划执行率</div>
      <div class="count">{{ item.value }}%</div>
    </div>
    <div class="item-right" :ref="item.id"></div>
  </div>
</template>
<script>
import *as  echarts from 'echarts'
import {computedXY} from '@/views/businessExecution/hooks'

export default {
  name: "ring1",
  emits: ["swiperChange"],
  props: {
    activeSwiper: String,
    item: Object
  },
  data(){
    return{
    }
  },
  methods: {
    swiperChange(val) {
      this.$emit("swiperChange", val);
    },
    init() {
      const  chart = echarts.init(this.$refs[this.item.id]);
      const  {width,height}=this.$refs[this.item.id].getBoundingClientRect()
      const  {markLineData,labelPosition}=computedXY(this.item.value,width,height)
      const  option = {
        tooltip: {
          trigger: "item"
        },
        legend: {
          show: false
        },
        polar: {
          center: ["50%", "50%"],
          radius: ["50%", "100%"]
        },
        angleAxis: {
          max: 100,
          show: false
        },
        radiusAxis: {
          type: "category",
          show: true,
          axisLabel: {
            show: false
          },
          axisLine: {
            show: false
          },
          axisTick: {
            show: false
          }
        },
        series: [
          {
            data: [this.item.value],
            name: "",
            type: "bar",
            roundCap: false,
            showBackground: true,
            backgroundStyle: {
              color: "#ddd"
            },
            coordinateSystem: "polar",
            itemStyle: {
              normal: {
                color: "#005DCF"
              }
            },
            markLine:{
              symbol:['none'],
              silent:true,
              lineStyle:{
                color :'red',
                type: 'solid' ,
              },
              label:{
                position:labelPosition
              },
              data:markLineData,
            }
          },
        ]
      };
      chart.setOption(option);
      window.onresize = () => {
        chart.resize();
      };
    }
  },
  mounted() {
    this.init();
  }
};
</script>

<style scoped lang="scss">
.swiper-item {
  width: 25%;
  display: flex;
  padding:0 40px;
  box-sizing: border-box;
  &.active {
    background: #e6eefd;
    border-top: 2px solid #5eb3f0;
  }
  .item-left {
    width: 40%;
    .text-1 {
      padding: 16px 0;
      font-size: 16px;
      margin-bottom: 10px;
    }
    .text-2 {
      font-size: 14px;
      margin-bottom: 5px;
      color: #6b7d96;
    }
    .count {
      font-size: 26px;
      font-weight: bold;
    }
  }
  .item-right {
    width: 60%;
    height: 100%;
  }
}
</style>
